<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" media="screen" type="text/css" href="__THEMES__/style/layout.css" />
		<script type="text/javascript" src="__JS__/jQuery/jquery.js"></script>
		<script type="text/javascript" src="__JS__/jQuery/plugin/jquery.filestyle.js"></script>
		<script type="text/javascript" src="__JS__/jQuery/plugin/ajaxfileupload/ajaxfileupload.js"></script>
		<script type="text/javascript">
			$(function(){
				$("input[type=file]").filestyle({ image : "__THEMES__/images/chk.png", imageheight : 25, imagewidth : 86, width : 260 });
			});
			function ajaxFileUpload(){
                if ($("#filedata").val() == ''){
                    setAlertBox('请选择要上传的文件！', 2);
                    return false;
                }else{
                    $.post("__APP__/Uploadfile/removefile",{
                    	file:"<?php if(isset($vo['banner']) && !empty($vo['banner'])){ echo $vo['banner']; } ?>"
                    },function(data){
                    	if ( data.status == 1 ){
                    		$('#old_banner').remove();
                    	}
                    },'json');
                }
                //starting setting some animation when the ajax starts and completes
                $("#loading").ajaxStart(function(){ $(this).show(); }).ajaxComplete(function(){ $(this).hide(); });
        
                $.ajaxFileUpload({
                    url:'__APP__/uploadfile/upfile', 
                    secureuri:false,
                    fileElementId:'filedata',
                    dataType: 'json',
                    success: function (data, status){
                        //alert(data.msg.url);
                        if(typeof(data.error) != 'undefined'){
                            if(data.error != ''){
                                alert(data.error);
                            }else{
                                alert(data.msg);
                            }
                        }
                        $("#set_banner").after("<tr id='banner_display'><td></td><td align='left'><img src='"+data.msg.url+"' /><input type='hidden' name='banner' value='"+data.msg.url+"' /></td></tr>");
                        $("#buttonUpload").attr("disabled","disabled");
                        $("#filedata").attr("disabled","disabled");
                        $("#buttonUpload").after("&nbsp;&nbsp;<button class='attButton' id='removebanner' onclick=\"return removeFile(this,'"+data.msg.url+"');\">删除Banner</botton>");
                    },
                    error: function (data, status, e){
                        alert(e);
                    }
                });
                return false;
            }
            function removeFile(e,s){
				$.post("{:U('uploadfile/removefile')}",{
					file:s
				},function(data){
					if ( data.status == 1 ){
						$("#buttonUpload").removeAttr("disabled");
						$("#filedata").removeAttr("disabled");
						$("#banner_display").remove();
						$(e).remove();
					}
				},'json');
				return false;
			}
		</script>
		<style type="text/css">
			.form_table td	{ border:0; }
			.file_d_Upload	{ position: relative; height: 26px; display:block; }
			.attText		{ border: 1px solid #DDDDDD;font-family: verdana; font-size: 12px;padding: 4px!important;width: 460px; height:15px; }
			#buttonUpload	{ position:absolute; margin-left:96px; height:25px; padding:0 10px; cursor:pointer; vertical-align:middle; font-size:12px; word-break:keep-all;  white-space:nowrap; }
			#removebanner	{ position:absolute; margin-left:170px; height:25px; padding:0 10px; cursor:pointer; vertical-align:middle; font-size:12px; word-break:keep-all;  white-space:nowrap; }
		</style>
	</head>
	<body>
		
		<include file="Public:position" />
		
		<ul class="act_this">
    		<li<?php if($vo['type'] == 'index_banner'){ ?> class="this"<?php } ?>><a href="{:U('index',array('tag'=>$_GET['tag']))}">首页轮换广告</a></li>
    		<li<?php if($vo['type'] == 'about'){ ?> class="this"<?php } ?>><a href="{:U('index',array('tag'=>$_GET['tag'],'type'=>'about'))}">关于我们(首页)</a></li>
    		<li<?php if($vo['type'] == 'allfree'){ ?> class="this"<?php } ?>><a href="{:U('index',array('tag'=>$_GET['tag'],'type'=>'allfree'))}">自由定制广告</a></li>
    	</ul>
        
        <div class="a_table" style="position:relative;top:-1px;_top:-2px;">
            <form action="__URL__/update" method="post">
            <input type="hidden" name="id" id="id" value="{$vo.id}" />
            <input type="hidden" name="type" id="type" value="{$vo.type}" />
            <table width="100%" class="form_table">
            	<tr>
            		<td></td>
            		<td></td>
            	</tr>
                <tr>
                    <td align="right">标题</td>
                    <td align="left"><input type="text" name="title" class="input_text w480" value="{$vo.title}" /></td>
                </tr>
                <tr>
                    <td align="right">广告链接</td>
                    <td align="left"><input type="text" name="url" class="input_text w480" value="{$vo.url}" /></td>
                </tr>
                <tr id="set_banner">
					<td align="right" class="left_text">分类Banner设置</td>
					<td align="left">
						<span class="file_d_Upload">
							<php>if (!empty($vo['banner'])){</php>
							<input id="filedata" type="file" class="attText" name="filedata" disabled="disabled" />
							<button class="attButton" id="buttonUpload" onclick="return ajaxFileUpload();" disabled="disabled">上传文件</button>
							<button class='attButton' id='removebanner' onclick="return removeFile(this,'{$vo["banner"]}');">删除Banner</botton>
							<php>}else{</php>
							<input id="filedata" type="file" class="attText" name="filedata" />
							<button class="attButton" id="buttonUpload" onclick="return ajaxFileUpload();">上传文件</button>
							<php>}</php>
						</span>
					</td>
				</tr>
				<php>if (!empty($vo['banner'])){</php>
				<tr id='banner_display'>
					<td></td>
					<td align='left'><img src='{$vo['banner']}' /><input type='hidden' name='banner' value='{$vo['banner']}' /></td>
				</tr>
				<php>}</php>
				<tr style="display:none;" id="loading">
					<td></td>
					<td align='left'><img src="__THEMES__/images/loading.gif" /></td>
				</tr>
                <tr>
                    <td align="right">状态</td>
                    <td align="left">
                        <input type="radio" name="status" value="1"<eq name="vo.status" value="1" > checked="checked"</eq> /> 显示 &nbsp;&nbsp;
                        <input type="radio" name="status" value="0"<eq name="vo.status" value="0" > checked="checked"</eq> /> 隐藏 &nbsp;&nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right">详细说明</td>
                    <td align="left"><textarea name="dsp" id="dsp" style="width: 90%; height:160px;" class="input_text">{$vo.dsp}</textarea></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td align="left"><input type="submit" class="submit" value="提交表单" /></td>
                </tr>
                <tr>
            		<td></td>
            		<td></td>
            	</tr>
            </table>
            </form>
        </div>
	</body>
</html>